package com.iwhalecloud.uncc.archiver.impl;

import com.iwhalecloud.uncc.archiver.Archiver;
import com.iwhalecloud.uncc.common.DataSourceHelp;
import com.iwhalecloud.uncc.common.SpringContext;
import com.iwhalecloud.uncc.model.InsCollectTask;
import com.iwhalecloud.uncc.service.ArchiverService;
import lombok.extern.slf4j.Slf4j;


/**
 * @author zq
 * @date 2021/10/15 15:35
 * @description InsCollectTaskArchiver
 */

@Slf4j
public class InsCollectTaskArchiver implements Archiver {

    private ArchiverService<InsCollectTask> insCollectTaskArchiverService =
            (ArchiverService<InsCollectTask>) SpringContext.getContext().getBean("insCollectTaskArchiverService");

    private DataSourceHelp dataSourceHelp =
            (DataSourceHelp) SpringContext.getContext().getBean("dataSourceHelp");
    /**
     * 归档 InsCollectTask 关联  每个分片启动一个线程
     */
    @Override
    public void archive() {
        if (log.isInfoEnabled()) {
            log.info("InsCollectTaskArchiver 提交归档任务...");
        }

        dataSourceHelp.getOnlineDatasource()
                .forEach(i->insCollectTaskArchiverService.archive(i.getCode()));

//        List<UnccDsProperties.UnccDsConfig> ucDataSourceList = getOnlineDatasource();
//        for (UnccDsProperties.UnccDsConfig unccDsConfig : ucDataSourceList) {
//            insCollectTaskArchiverService.archiveInsCollectTask(unccDsConfig.getCode());
//        }

    }

//    private List<UnccDsProperties.UnccDsConfig> getOnlineDatasource() {
//        return unccDsProperties.getBizDatasource().stream()
//                .filter(i -> !i.getCode().startsWith(ArchiverConstant.HIS))
//                .collect(Collectors.toList());
//    }
}
